package com.cras.webcam.http.handler.codec;


import com.cras.webcam.http.HttpMessage;
import com.cras.webcam.http.HttpMethod;
import com.cras.webcam.http.HttpRequest;
import com.cras.webcam.http.HttpVersion;

/**
 * Created by cras on 2017/6/24 0024.
 */

public class HttpRequestDecoder extends ObjectDecoder {
    public HttpRequestDecoder() {
    }

    /**
     * Creates a new instance with the specified parameters.
     */
    public HttpRequestDecoder(
            int maxInitialLineLength, int maxHeaderSize, int maxChunkSize) {
        super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true);
    }

    public HttpRequestDecoder(
            int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean validateHeaders) {
        super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders);
    }

    @Override
    protected HttpMessage createMessage(String[] initialLine) throws Exception {
        return new HttpRequest(
                HttpVersion.valueOf(initialLine[2]),
                HttpMethod.valueOf(initialLine[0]), initialLine[1]);
    }


    @Override
    protected HttpMessage createInvalidMessage() {
        return new HttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/bad-request");
    }

    @Override
    protected boolean isDecodingRequest() {
        return true;
    }
}
